package easy;

import java.util.ArrayList;
import java.util.List;

public class Solution_401 {

    /*public static List<String> readBinaryWatch(int num) {
        List<String> list = new ArrayList<>();
        if (num>8) {
            return list;
        }
        int[][] h = new int[][]{{0},{1,2,4,8},{3,5,6,9,10},{7,11}};
        int[][] m = new int[][]{{0},{1,2,4,8,16,32},{3,5,6,9,10,12,17,18,20,24,33,34,36,40,48},
            {7,11,13,14,19,21,22,25,26,28,35,37,38,41,42,44,49,50,52,56},
            {15,23,27,29,30,39,43,45,46,51,53,54,57,58},{31,47,55,59}};
        int highNumMin = Math.max(0, num-5);
        int highNumMax = Math.min(3, num);
        for (int i = highNumMin; i <= highNumMax; i++) {
            int j = num - i;
            for (int i1 : h[i]) {
                for (int i2 : m[j]) {
                    list.add(i1+(i2<10?":0":":") +i2);
                }
            }
        }
        Collections.sort(list);
        return list;
    }*/

    public static void main(String[] args) {
        Solution_401 m = new Solution_401();
        System.out.println(m.readBinaryWatch(1));
    }

    int[] time = { 1, 2, 4, 8, 16, 32, 1, 2, 4, 8 };// 分+时
    List<String> res = new ArrayList<>();

    public List<String> readBinaryWatch(int num) {
        dfs(num, 0, 0, 0);
        return res;
    }

    public void dfs(int num, int begin, int hour, int minute) {
        if (num == 0) {
            if (minute >= 60 || hour >= 12) {
                return;
            }
            StringBuilder temp = new StringBuilder();
            temp.append(hour);
            temp.append(":");
            if (minute < 10) {
                temp.append(0);
            }
            temp.append(minute);
            res.add(temp.toString());
//            System.out.println(hour + " ," + minute);
            return;
        }
        for (int i = begin; i < time.length; i++) {
            dfs(num, i + 1, hour, minute);
            if (i > 5) {
                hour += time[i];
            } else {
                minute += time[i];
            }
            dfs(num - 1, i + 1, hour, minute);
        }
    }
}
